<template>
<!--测评2-->
  <div>
    <ceping>
      <ul class="step">
        <li class="active">
          <p>基本资料</p>
          <span></span>
        </li>
        <li class="active">
          <p>教育经历</p>
          <span></span>
        </li>
        <li class="active">
          <p>工作经历</p>
          <span></span>
        </li>
        <li>
          <p>能力测评</p>
          <span></span>
        </li>
      </ul>
      <div class="ceping_form">
        <Form ref="ceping3form" :model="workcourse" :label-width="102" :rules="ceping3Validate">
            <FormItem label="公司名称" prop="companyName">
              <Input v-model="workcourse.companyName" placeholder="请输入公司名称" :maxlength="45"/>
            </FormItem>
            <FormItem label="职位名称" prop="position">
              <Select  v-model="workcourse.position" placeholder="请选择职位" >
                <Option :value="post.code" v-for="post in posts" :key="post.code">{{post.name}}</Option>
              </Select>
            </FormItem>
            <FormItem label="业态" prop="operationType">
              <Select  v-model="workcourse.operationType" placeholder="请选择业态">
                <Option :value="com.code" v-for="com in commercials" :key="com.code">{{com.name}}</Option>
              </Select>
            </FormItem>
            <FormItem label="工作年限"  prop="workingLife">
              <Select  v-model="workcourse.workingLife" placeholder="请选择工作年限">
                <Option :value="year.name" v-for="year in workingYears" :key="year.name">{{year.text}}</Option>
              </Select>
            </FormItem>
            <FormItem label="工作描述" style="width: 745px" prop="workTask">
              <Input type="textarea" :autosize="{minRows: 6,maxRows: 7}" placeholder="赶快添加工作描述吧~" v-model="workcourse.workTask" :maxlength="450"/>
              <p class="tip">注：请填写真实工作经历，我们平台会对你提交的资料做背景调查，如虚假将加入企业黑名单。</p>
            </FormItem>
          <!--</div>-->
          <FormItem class="addjob" style="width: 600px">
            <Button class="" @click="save('ceping3form')"><Icon type="ios-add-circle-outline" size="25"/>增加工作经历</Button>
            <Button class="" @click="next">无工作经历</Button>
          </FormItem>
          <FormItem>
            <Button class="nextbtn" @click="next">下一步</Button>
          </FormItem>
        </Form>
      </div>
      <Spin fix v-show="isSpinShow" >
        <div class="loader">
          <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
          <div class="font14">加载中...</div>
        </div>
      </Spin>
    </ceping>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }


  .banner{
    height: 360px;
  }
  .divider{
    height: 53px;
    background-color: #fff;
    font-size: 14px;
    color: #957960;
    line-height: 53px;
    text-align: left;
    margin-bottom: 30px;
    box-shadow: 5px 1px 10px #ccc;
    a{
      color: #957960;
      &:hover{
        color: #9C7649;
        font-weight: 700;
      }
    }
    span{
      margin: 0 10px;
    }
  }

  .content .container .step li:nth-child(3) span:after{
    left: 30px;
  }
  form{
    width: 360px;
    margin:50px  0 0 50px ;
    .tip{
      font-size: 14px;
      color: #666;
      margin: 10px 0 0;
    }
    .addjob {
      button{
        border-color: #e6e6e6;
        height: 44px;
        width: 209px;
        font-size: 16px;
        color: #999;
      }
      button:first-child{
        margin-right: 20px;
        i{
          margin-right: 5px;
        }
      }
    }
  }
.nextbtn{
  background-color: #957960;
  height: 55px;
  width: 221px;
  font-size: 18px;
  color: #fff;
}
  .step li:nth-child(1).active, .step li:nth-child(2).active{
    span:after{
      background-color: #957960 !important;
    }
  }
</style>
<script type="text/ecmascript-6">
  import ceping from '../template/ceping'
  import {workCourseAdd,workCourseSubmit,centreInfoWeb,abilityPage} from '../../http'
  import {getStore} from "../../storage";

  export default {
        name: 'ceping2',
        props: {},
        data() {
            return {
              isSpinShow:false,
              commercials:'',         //业态
              posts:'',               //职位名称
              workingYears:'',        //工作年限
              workcourse:{            //工作经历
                companyName:'',
                operationType:'',
                position:'',
                workingLife:'',
                workTask:'',
              },
              //工作经历表单验证规则
              ceping3Validate: {
                companyName: [
                  { required: true, message: '请填写公司名称', trigger: 'blur' }
                ],
                position: [
                  { required: true, message: '请选择职位', trigger: 'change' }
                ],
                operationType: [
                  { required: true, message: '请选择业态', trigger: 'change' },
                ],
                workingLife: [
                  { required: true, message: '请选择工作年限', trigger: 'change' }
                ],
                workTask: [
                  { required: true, message: '请填写工作描述',trigger: 'blur' },
                ],
              }
            };
        },
        methods: {
          next(){
              this.$router.push({
                name: 'ceping4'
              })
          },
          save (name) {
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              this.$refs[name].validate((valid) => {
                if (valid) {
                  //用户是否登录
                  centreInfoWeb().then(res => {
                    if (res.code === 200) {
                      workCourseSubmit({
                        companyName: this.workcourse.companyName,
                        operationType: this.workcourse.operationType,
                        position: this.workcourse.position,
                        workingLife: this.workcourse.workingLife,
                        workTask: this.workcourse.workTask
                      }).then(res => {
                        this.isSpinShow = false;
                        if (res.code === 200) {
                          this.$Notice.success({
                            title: "人才测评提醒",
                            desc: '工作经历添加成功',
                            duration: 3,
                          });
                          this.$refs[name].resetFields();
                        }else {
                          this.$Notice.warning({
                            title: "人才测评提醒",
                            desc: res.info,
                            duration: 3,
                          });
                        }
                      }).catch()
                    } else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: '登录提醒 ',
                        desc: '使用人才测评，需用户登录！ ',
                        duration: 3,
                      });
                      this.$router.push({name: 'ceping'});
                    }
                  }).catch()
                } else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: "人才测评提醒",
                    desc: "工作经历添加失败！",
                    duration: 3,
                  });
                }
              }).catch()
            }
          },
          getCeping3(){
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //获取工作经历页面数据
                  abilityPage().then(res => {
                    if (res.code === 200) {
                      if (res.data.isBuy === 1) {
                        workCourseAdd().then(res => {
                          if(res.code === 200) {
                            this.isSpinShow = false;
                            this.commercials = res.data.commercials;
                            this.posts = res.data.posts;
                            this.workingYears = res.data.workingYears;
                          }else {
                            this.isSpinShow = false;
                            this.$Notice.warning({
                              title: "人才测评提醒",
                              desc: res.info,
                              duration: 3,
                            });
                          }
                        }).catch()
                      } else {
                        this.isSpinShow = false;
                        this.$Notice.warning({
                          title: "人才测评提醒",
                          desc: "请先购买人才能力测评",
                          duration: 3,
                        });
                        this.$router.push({
                          name: 'ceping'
                        })
                      }
                    }else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "人才测评提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch()
                } else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: '登录提醒 ',
                    desc: '使用人才测评，需用户登录！ ',
                    duration: 3,
                  });
                  this.$router.push({name: 'ceping'});
                }
              })
            }
          }
        },
        created() {
          /*this.$router.push({
            name:'ceping'
          })*/
          this.getCeping3();
        },
        components: {
          ceping
        }
    }
</script>
